﻿using System;
using System.Collections;
namespace Program19
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] nums1 = new  int [10];
            ArrayList arr = new ArrayList();
            Random rnd = new Random();
            Console.WriteLine("初始化数组：");

            while (arr.Count < 100)
            {
                int tmpnum = rnd.Next(1, 100);
                if (!arr.Contains(tmpnum))
                {
                    arr.Add(tmpnum);
                }
            }
            for (var i = 0; i < nums1.Length; i++)
            {
                nums1[i] = (int)arr[i];
                Console.Write(nums1[i] + " ");
            }
            Console.WriteLine();


            int max, min, sum;
            double avg;
            Group(nums1, out max, out min, out avg, out sum);
            Console.WriteLine("最大值：" + max);
            Console.WriteLine("最小值：" + min);
            Console.WriteLine("总和为：" + sum);
            Console.WriteLine("平均值：" + avg);

        }
        //编写一个方法，求出一个数组的最大值，最小值，平均值和总和。
        //多个返回值的方法，out参数
        //out参数要求在方法内部必须赋值，并且定义在形参末尾

        public static void Group(int[] nums, out int max, out int min, out double avg, out int sum)
        {
            max = nums[0];
            min = nums[0];
            sum = 0;
            avg = 0.0;

            for (var i = 0; i < nums.Length; i++)
            {
                if (nums[i] > max)
                    max = nums[i];
                if (nums[i] < min)
                    sum += nums[i];                                  
            }
            avg = (double)(sum / nums.Length);
        }

    }
}
